cdef class BourbonObject:
	cpdef object results(self):
		return {}
		
	cpdef object params(self):
		return {}

	def __getstate__(self):
		return {}
		
	def __setstate__(self, data):
		pass
	

cdef class Job(BourbonObject):
	
	def __init__(self):
		self.status = INITIALIZED
		self._params = {}
		
	
	cpdef int start(self):
		if self.status <> INITIALIZED: return 0
		
		self.status = STARTED
		return 1
	
	cpdef object results(self):
		"""Return a dictionary of results."""
		cdef object result = BourbonObject.results(self)
		
		return result
		
	
	cpdef object params(self):
		"""Return a dictionary of parameters."""
		cdef object param = BourbonObject.params(self)
		
		param.update(self._params)
		param['Job.Class'] = str(self.__class__.__name__)
		return param
		
	cpdef advance(self, double percent=1.0):
		"""Extensions should define advancement in the experiment (simulation) by a given percent.  
		
		For instance, if percent is 0.5, then the experiment should advance to 50% completion.
		"""
		pass
		
	cpdef int finalize(self):
		if self.status <> FINISHED: return 0
		
		self.status = FINALIZED
		return 1
		
	cpdef add_param(self, object name, object value):
		"""Add a parameter to the experiment"""
		self._params["Base.%s"%str(name)] = value
		
	cpdef int is_finalized(self):
		return self.status == FINALIZED
		
	cpdef int is_started(self):
		return self.status == STARTED
		
	cpdef int is_finished(self):
		return self.status == FINISHED
	
	def __getstate__(self):
		data = {}
		data['status'] = self.status
		data['params'] = self._params
		return data

	def __setstate__(self, data):
		self.status = data['status']
		self._params = data['params']
		
	def __reduce__(self):
		return (Job,(), self.__getstate__() )
